﻿using System;
using System.Data;
using System.IO;
using Excel;
using UnityEngine;

public static class ExcelLoader
{
    public static void Load(string fileName)
    {
        try {
            byte[] bytes = Utility.SafeReadAllByte(fileName, Utility.UnityPathType.persistentDataPath);
            MemoryStream stream = new MemoryStream(bytes);

            IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
            //表格数据全部读到result
            DataSet result = excelReader.AsDataSet();

            ////表格有多少列
            //int columns = result.Tables[0].Columns.Count;
            ////表格有多少行
            //int rows = result.Tables[0].Rows.Count;
            ////rows = 10;
            ////rows = 500;
            //Debug.Log("rows:" + rows);
            stream.Close();
            excelReader.Close();
        }
        catch (Exception e) {
            Debug.LogError(e.Message);
            throw;
        }
    }
}
